package com.rachel.testjetpack;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.rachel.testjetpack.livedata.Main4ActivityViewModel;
import com.rachel.testjetpack.livedata.Main4ActivityViewModelFactory;
import com.rachel.testjetpack.viewmodel.Main3ActivityViewModel;
import com.rachel.testjetpack.viewmodel.Main3ActivityViewModelFactory;

/**
 * LiveData
 */
public class Main4Activity extends AppCompatActivity implements LifecycleOwner {
   private LifecycleRegistry lifecycleRegistry;
    private int inputCount = 100;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mian3);
        lifecycleRegistry = new LifecycleRegistry(this);
        Main4ActivityViewModel viewModel ;
        viewModel = new ViewModelProvider(this,new Main4ActivityViewModelFactory(inputCount)).get(Main4ActivityViewModel.class);
        getLifecycle().addObserver(new WorkUtil4(viewModel));
        viewModel.getCount().observeForever(new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {

            }
        });
    }

    @NonNull
    @Override
    public Lifecycle getLifecycle() {
        return lifecycleRegistry;
    }
}
